package com.handle.common.core.dto;


import com.handle.common.core.utils.StringUtils;
import lombok.Data;

/**
 * 分页对象
 *
 * @author zhangqing
 */
@Data
public class PageDomain {
    /**
     * 当前记录起始索引
     */
    private Integer pageNum;
    /**
     * 每页显示记录数
     */
    private Integer pageSize;
    /**
     * 排序列
     */
    private String orderByColumn;
    /**
     * 排序的方向 "desc" 或者 "asc".
     */
    private String isAsc;

    public PageDomain(Integer pageNum, Integer pageSize, String orderByColumn, String isAsc) {
        this.pageNum = pageNum.equals(0) ? 1 : pageNum;
        this.pageSize = pageSize.equals(0) ? 10 : pageSize;
        this.orderByColumn = orderByColumn;
        this.isAsc = isAsc;
    }

    public String getOrderBy() {
        if (StringUtils.isEmpty(orderByColumn)) {
            return "";
        }
        return StringUtils.toUnderScoreCase(orderByColumn) + " " + isAsc;
    }
}
